package com.rosiminc.pm.game.tiles;

import com.rosiminc.pm.game.Tile;

/**
 * This object represents a rotating tile.
 * 
 * @author Shymon
 * 
 */
public class RotateTile extends GameBoardTile {

	private Tile tile;

	/**
	 * This constructor initialises the tile with given row, column and pipe
	 * tile.
	 * 
	 * @param row
	 *            the row
	 * @param col
	 *            the column
	 * @param tile
	 *            the pipe tile
	 * @throws IllegalArgumentException
	 *             if the tile is null
	 */
	public RotateTile(int row, int col, Tile tile) {
		super(row, col);

		if (tile == null)
			throw new IllegalArgumentException("Null tile sent");
		this.tile = tile;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.rosiminc.pm.game.tiles.GameBoardTile#actionA()
	 */
	@Override
	public void actionA() {
		this.tile = this.tile.rotateRight();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.rosiminc.pm.game.tiles.GameBoardTile#actionB()
	 */
	@Override
	public void actionB() {
		this.tile = this.tile.rotateLeft();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.rosiminc.pm.game.tiles.GameBoardTile#shuffle()
	 */
	@Override
	public void shuffle() {
		for (int i = (int) (Math.random() * 4); i > 0; i--)
			actionA();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.rosiminc.pm.game.tiles.GameBoardTile#getTile()
	 */
	@Override
	public Tile getTile() {
		return this.tile;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.rosiminc.pm.game.tiles.GameBoardTile#getTileType()
	 */
	@Override
	public TileType getTileType() {
		return TileType.ROTATE;
	}
}
